package com.pri.chat.nim.session.viewholder;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.netease.nim.uikit.net.SharedHelper;
import com.pri.chat.R;
import com.pri.chat.activity.DTmsgActivity;
import com.pri.chat.activity.OtherPeopleMsgActivity;
import com.pri.chat.activity.VedioMsgActivity;
import com.pri.chat.activity.WishMsgActivity;
import com.pri.chat.nim.session.extension.ShareAttachment;
import com.vondear.rxtool.RxActivityTool;

/**
 * 类描述：
 *
 * @author mhd
 */
public class MsgViewHolderShare extends MsgViewHolderBase {

    private View otherLinear;
    private ImageView other_image;
    private TextView other_title;
    private TextView other_content;
    private ImageView other_vedioImg;
    private ImageView other_logo;
    private TextView other_name;


    private View meLinear;
    private ImageView me_image;
    private TextView me_title;
    private TextView me_content;
    private ImageView me_vedioImg;
    private ImageView me_logo;
    private TextView me_name;

    public MsgViewHolderShare(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }

    @Override
    public int getContentResId() {
        return R.layout.item_message_share;
    }

    @Override
    public void inflateContentView() {
        otherLinear = findViewById(R.id.otherLinear);
        other_image = findViewById(R.id.other_image);
        other_title = findViewById(R.id.other_title);
        other_content = findViewById(R.id.other_content);
        other_vedioImg = findViewById(R.id.other_videoImg);
        other_name = findViewById(R.id.other_name);
        other_logo = findViewById(R.id.other_logo);

        meLinear = findViewById(R.id.meLinear);
        me_image = findViewById(R.id.me_image);
        me_title = findViewById(R.id.me_title);
        me_content = findViewById(R.id.me_content);
        me_vedioImg = findViewById(R.id.me_videoImg);
        me_name = findViewById(R.id.me_name);
        me_logo = findViewById(R.id.me_logo);
    }

    private static final String TAG = "MsgViewHolderShare";
    @Override
    public void bindContentView() {
        ShareAttachment attachment = (ShareAttachment) message.getAttachment();
        String imageUrl = attachment.getImageUrl();
        String describe = attachment.getDescribe();
        String title = attachment.getTitle();
        int type = attachment.getType();
        String id = attachment.getId();

        if(SharedHelper.readId(context).equals(message.getFromAccount())){
            Glide.with(context).load(imageUrl).error(com.netease.nim.uikit.R.drawable.nim_default_img_failed).into(me_image);
            me_content.setText(describe);
            me_title.setText(title);
            meLinear.setVisibility(View.VISIBLE);
            otherLinear.setVisibility(View.GONE);
            me_vedioImg.setVisibility(View.GONE);
            if(type == 0){
                me_logo.setImageResource(R.drawable.ic_dongtai_logo);
                me_name.setText("动态");
            }else if(type == 1){
                me_logo.setImageResource(R.drawable.ic_yuanwang);
                me_name.setText("愿望");
            }else if(type == 2){
                me_logo.setImageResource(R.drawable.ic_vedio);
                me_name.setText("视频");
                me_vedioImg.setVisibility(View.VISIBLE);
            }else if(type == 3){
                me_logo.setImageResource(R.mipmap.ic_jiasu);
                me_name.setText("加速");
                me_vedioImg.setVisibility(View.GONE);
            }

        }else{
            Glide.with(context).load(imageUrl).error(com.netease.nim.uikit.R.drawable.nim_default_img_failed).into(other_image);
            other_content.setText(describe);
            other_title.setText(title);
            meLinear.setVisibility(View.GONE);
            otherLinear.setVisibility(View.VISIBLE);
            other_vedioImg.setVisibility(View.GONE);
            if(type == 0){
                other_logo.setImageResource(R.drawable.ic_dongtai_logo);
                other_name.setText("动态");
            }else if(type == 1){
                other_logo.setImageResource(R.drawable.ic_yuanwang);
                other_name.setText("愿望");

            }else if(type == 2){
                other_logo.setImageResource(R.drawable.ic_vedio);
                other_name.setText("视频");
                other_vedioImg.setVisibility(View.VISIBLE);
            }else if(type == 3){
                me_logo.setImageResource(R.mipmap.ic_jiasu);
                me_name.setText("加速");
                me_vedioImg.setVisibility(View.GONE);
            }
        }
        otherLinear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(type == 0){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, DTmsgActivity.class,bundle);
                }else if(type == 1){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, WishMsgActivity.class,bundle);
                }else if(type == 2){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, VedioMsgActivity.class,bundle);
                }else if(type == 3){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, OtherPeopleMsgActivity.class,bundle);
                }
            }
        });
        meLinear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(type == 0){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, DTmsgActivity.class,bundle);
                }else if(type == 1){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, WishMsgActivity.class,bundle);
                }else if(type == 2){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, VedioMsgActivity.class,bundle);
                }else if(type == 3){
                    Bundle bundle = new Bundle();
                    bundle.putString("id",id);
                    RxActivityTool.skipActivity(context, OtherPeopleMsgActivity.class,bundle);
                }
            }
        });
    }

    @Override
    protected boolean isShowBubble() {
        return false;
    }

}
